# -*- coding=utf-8 -*-

"""
fuwa model
"""
from framework.mongo import MongoModel

class FuwaModel(MongoModel):
    """fuwa chat model"""

    def __init__(self):
        """super init"""
        super(FuwaModel, self).__init__()

    def return_coll(self):
        """return databae name and collection name"""
        return 'fuwa', 'view'

    def get_last_count(self):
        """get view list"""
        # recent last 15 records
        last = self.find().sort([("sync_time", -1)])[0:10]
        if not last:
            return
        # sort record on asc
        l = list()
        for i in last:
            l.append(i)
        l = self.reverse_list(l)
        return l

    def reverse_list(self, l=list()):
        """reverse list"""
        if not isinstance(l, list) or not l:
            return
        max_offset = len(l) - 1
        temp_l = list()
        while max_offset >= 0:
            temp_l.append(l[max_offset])
            max_offset -= 1
        return temp_l
